package info.magnolia.blossom.sample.cv.components;

import info.magnolia.blossom.sample.cv.ListOfCVs;
import info.magnolia.module.blossom.annotation.TabFactory;
import info.magnolia.module.blossom.annotation.Template;
import info.magnolia.module.blossom.annotation.TemplateDescription;
import info.magnolia.module.blossom.dialog.TabBuilder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * Created with IntelliJ IDEA.
 * User: peterbalazs
 * Date: 2/27/13
 * Time: 2:46 PM
 * To change this template use File | Settings | File Templates.
 */
@Template(title = "Search CV Form", id = "blossomSample:components/searchcvform")
@TemplateDescription("Search Form for listing CVs")
@Controller
public class SearchCVFormComponent {

    @RequestMapping("/cvtemplate/searchcvform")
    public String render(final ModelMap model, final HttpServletRequest request) {
        String searchCriteria = request.getParameter(ListOfCVs.PARAM_CV_LIST_SEARCH_CRITERIA);
        if (searchCriteria == null) {
            searchCriteria = "";
        }
        model.put("criteria", searchCriteria);

        return "components/searchCVForm.jsp";
    }

    @TabFactory("Settings")
    public void settingsTab(final TabBuilder tab) {
        tab.addUuidLink("listLink", "List Link", "The page which will be loaded after the search button is pressed");
    }

    @TabFactory("Styling")
    public void stylingTab(final TabBuilder tab) {
        tab.addUuidLink("componentClass", "Component CSS Class", "CSS class(es) which will be added to the component's parent DIV");
    }
}
